﻿'------------------------------------------------------------------------------------------------
'@Người tạo : Nguyễn Văn Quỳnh
'@Ngày tạo  : 28/08/2010
'@Tên file  : frmNhatKy.vb
'@Chức năng : Hiển thị nhật ký sử dụng hệ thống
'------------------------------------------------------------------------------------------------

Imports Publics
Imports KT.DanhMuc
Imports KT.BaoCao
Imports KT.NhapLieu
Imports System.Windows.Forms

Public Class frmNhatKy

    Private _DenNgay As DateTime
    Public Property DenNgay() As DateTime
        Get
            Return _DenNgay
        End Get
        Set(ByVal value As DateTime)
            _DenNgay = value
        End Set
    End Property

    Private _TuNgay As DateTime
    Public Property TuNgay() As DateTime
        Get
            Return _TuNgay
        End Get
        Set(ByVal value As DateTime)
            _TuNgay = value
        End Set
    End Property

    Private Sub FillDataToGrid()
        If vUser.CanBo.UserName.ToLower = "superadmin" Then
            grdNhatKy.DataSource = (From p In dbTV.SYS_Logs Where p.ThoiDiem.Value.Date >= TuNgay.Date And p.ThoiDiem.Value.Date <= DenNgay.Date _
                                Order By p.ThoiDiem.Value Descending _
                                Select p.PhanMem, p.ChucNang, p.SuKien, p.NoiDung, _
                                ThoiDiem = Format(p.ThoiDiem, "dd/MM/yyyy hh:mm:ss tt"), _
                                p.DiaChiMAC, p.Username, p.ID_BanGhi, p.TenForm)
            grdNhatKy.RefreshDataSource()
        Else
            grdNhatKy.DataSource = (From p In dbTV.SYS_Logs Where p.ThoiDiem.Value.Date >= TuNgay.Date And p.ThoiDiem.Value.Date <= DenNgay.Date _
                                    Where p.Username.ToLower <> "superadmin" _
                                Order By p.ThoiDiem.Value Descending _
                                Select p.PhanMem, p.ChucNang, p.SuKien, p.NoiDung, _
                                ThoiDiem = Format(p.ThoiDiem, "dd/MM/yyyy hh:mm:ss tt"), _
                                p.DiaChiMAC, p.Username, p.ID_BanGhi, p.TenForm)
            grdNhatKy.RefreshDataSource()
        End If
        
    End Sub

    Private Sub frmNhatKy_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
        'If e.KeyCode = Keys.Escape Then
        '    Me.Close()
        'End If
        If (e.Modifiers = GetKeyModifide(pIdLamTuoi) And _
            e.KeyCode = GetKeyCode2(pIdLamTuoi)) Or _
            (e.KeyCode = GetKeyCode(pIdLamTuoi)) Then

            If bntLamTuoi.Enabled = True And bntLamTuoi.Visibility = DevExpress.XtraBars.BarItemVisibility.Always Then
                bntLamTuoi_ItemClick(Nothing, Nothing)
            End If
        End If

        If (e.Modifiers = GetKeyModifide(pIdTroGiup) And _
            e.KeyCode = GetKeyCode2(pIdTroGiup)) Or _
            (e.KeyCode = GetKeyCode(pIdTroGiup)) Then

            If btnTroGiup.Enabled = True And btnTroGiup.Visibility = DevExpress.XtraBars.BarItemVisibility.Always Then
                btnTroGiup_ItemClick(Nothing, Nothing)
            End If
        End If

        If (e.Modifiers = GetKeyModifide(pIdThoat) And _
           e.KeyCode = GetKeyCode2(pIdThoat)) Or _
           (e.KeyCode = GetKeyCode(pIdThoat)) Then

            btnHuy_ItemClick(Nothing, Nothing)
        End If
    End Sub

    Private Sub frmNhatKy_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        FillDataToGrid()
        Me.KeyPreview = True
        Me.Text = "Nhật ký hệ thống"
    End Sub

    Private Sub bntXuat_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles bntXuat.ItemClick
        Export_Dialog(SaveFileDialog1, grdNhatKy, "xls")
    End Sub

    Private Sub bntLamTuoi_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles bntLamTuoi.ItemClick
        FillDataToGrid()
    End Sub

    Private Sub btnTroGiup_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnTroGiup.ItemClick

    End Sub

    Private Sub btnHuy_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnHuy.ItemClick
        Me.Close()
    End Sub
     
    Public Sub New()
        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        ' Add any initialization after the InitializeComponent() call.
        grvNhatKy.OptionsView.ShowFilterPanelMode = DevExpress.XtraGrid.Views.Base.ShowFilterPanelMode.Default
        For Each item As DevExpress.XtraGrid.Columns.GridColumn In grvNhatKy.Columns
            If item.Equals(grdcolThoiDiem) = False Then
                item.OptionsFilter.AutoFilterCondition = DevExpress.XtraGrid.Columns.AutoFilterCondition.Contains
            End If
        Next
    End Sub

    Private Sub btnChonThoiGian_ItemClick(ByVal sender As System.Object, ByVal e As DevExpress.XtraBars.ItemClickEventArgs) Handles btnChonThoiGian.ItemClick
        Dim frm As New FrmThangNamBaoCao
        frm.ShowDialog()
        If frm.TuNgay IsNot Nothing AndAlso frm.DenNgay IsNot Nothing Then
            TuNgay = frm.TuNgay
            DenNgay = frm.DenNgay
            FillDataToGrid()
        End If
    End Sub

    Private Sub grvNhatKy_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles grvNhatKy.KeyDown
        If grvNhatKy.FocusedRowHandle = 0 AndAlso e.KeyCode = Windows.Forms.Keys.Up Then
            grvNhatKy.FocusedRowHandle = DevExpress.XtraGrid.GridControl.AutoFilterRowHandle
        End If
    End Sub
End Class